package edu.auctionmart

import edu.auctionmart.User
import edu.auctionmart.Feedback

class UserService {

    def getFeedbackReceivedForUser(User userInstance, params) {
		if (!params.max) {
			params.max = 5
		}
		def feedbackReceivedCriteria = Feedback.createCriteria()
		def feedbackReceivedResults = feedbackReceivedCriteria.list(params) {
			eq("leftFor", userInstance)
		}
		return feedbackReceivedResults
    }
	
	def getFeedbackGivenForUser(User userInstance, params) {
		if (!params.max) {
			params.max = 5
		}
		def feedbackGivenCriteria = Feedback.createCriteria()
		def feedbackGivenResults = feedbackGivenCriteria.list(params) {
			eq("leftBy", userInstance)
		}
		return feedbackGivenResults
	}
	
	def getFeedbackReceivedTotalForUser(User userInstance) {
		return Feedback.findAllByLeftFor(userInstance).size()
	}
	
	def getFeedbackGivenTotalForUser(User userInstance) {
		return Feedback.findAllByLeftBy(userInstance).size()
	}
}
